package web.dao.Impl;

import web.bean.Chewei;
import web.bean.Zichan;
import web.dao.ZichanDao;
import web.utils.DBUtil;

import java.util.List;

public class ZichanDaoImpl implements ZichanDao {
    @Override
    public int count(String startTime, String endTime, String name) {

        return DBUtil.findByWhere(Zichan.class, "addtime>=? and addtime<=? and suoshuxiaoqu like ? ", startTime, endTime, "%" + name + "%").size();
    }

    @Override
    public List<Zichan> findInfo(Integer params1, Integer params2, String startTime, String endTime, String name) {
        return DBUtil.findByWhere(Zichan.class, "addtime>=? and addtime<=? and suoshuxiaoqu like ?  limit ?,?", startTime, endTime, "%" + name + "%", params1, params2);

    }

    @Override
    public int add(Zichan zichan) {
        return DBUtil.insert(zichan);
    }

    @Override
    public int del(Integer[] deleteId) {
        String where="id in (";
        for (int i = 0; i < deleteId.length; i++) {
            where+="?";
            if (i!=deleteId.length-1){
                where+=",";
            }else {
                where+=")";
            }
        }
        return DBUtil.delete(Zichan.class,where,deleteId);
    }

    @Override
    public Zichan showZichan(Integer id) {
        return DBUtil.findOneByWhere(Zichan.class,"id=?",id);
    }

    @Override
    public int editInfo(Zichan zichan) {
        return DBUtil.updateSelective(zichan,"id=?",zichan.getId());
    }
}
